package com.ruoyi.system.service.vantservice.galleryservice.impl;

import com.ruoyi.system.domain.gallery.GalleryCase;
import com.ruoyi.system.domain.gallery.GalleryComment;
import com.ruoyi.system.domain.gallery.GalleryInfo;
import com.ruoyi.system.domain.gallery.GalleryOriginal;
import com.ruoyi.system.mapper.vant.gallery.ApiGalleryMapper;
import com.ruoyi.system.service.vantservice.galleryservice.ApiGalleryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApiGalleryServiceImpl implements ApiGalleryService {

    @Autowired
    private ApiGalleryMapper apiGalleryMapper;

    /**
     * 根据图库类别查询图库列表
     * @param galleryInfoType
     * @return
     */
    public List<GalleryInfo> selectGalleryInfoListByType(String galleryInfoType){
        return apiGalleryMapper.selectGalleryInfoListByType(galleryInfoType);
    }

    /**
     * 根据ID查询图库信息
     * @param galleryInfoId
     * @return
     */
    public GalleryOriginal selectGalleryInfoById(Long galleryInfoId){
        return apiGalleryMapper.selectGalleryInfoById(galleryInfoId);
    }

    /**
     * 查询案例说明列表
     * @param galleryOriginalId
     * @return
     */
    public List<GalleryCase> selectGalleryCasesList(Long galleryOriginalId){
        return apiGalleryMapper.selectGalleryCasesList(galleryOriginalId);
    }

    /**
     * 根据ID查询图库信息评论
     * @param galleryInfoId
     * @return
     */
    public List<GalleryComment> selectGalleryComment(Long galleryInfoId){
        return apiGalleryMapper.selectGalleryComment(galleryInfoId);
    }

    /**
     * 添加图库评论信息
     * @param galleryComment
     * @return
     */
    public int addGalleryComment(GalleryComment galleryComment){
        // 根据图库ID查询图库信息
        GalleryOriginal galleryOriginal = apiGalleryMapper.selectGalleryInfoById(galleryComment.getGalleryCommentInfo());
        GalleryInfo galleryInfo = galleryOriginal.getGalleryInfo();
        Long reply = galleryInfo.getGalleryInfoReply();
        galleryInfo = new GalleryInfo();
        galleryInfo.setGalleryInfoId(galleryComment.getGalleryCommentInfo());
        galleryInfo.setGalleryInfoReply((reply+1));
        if(apiGalleryMapper.addGalleryComment(galleryComment) > 0){
            return apiGalleryMapper.updateGalleryInfo(galleryInfo);
        }else{
            return 0;
        }
    }

    @Override
    public List<GalleryInfo> selectGalleryInfoListByTypeOne(GalleryInfo galleryInfo) {
        return apiGalleryMapper.selectGalleryInfoListByTypeOne(galleryInfo);
    }
    @Override
    public List<GalleryInfo> selectGalleryInfoListByTypeTwo(GalleryInfo galleryInfo) {
        return apiGalleryMapper.selectGalleryInfoListByTypeTwo(galleryInfo);
    }

    @Override
    public List<GalleryInfo> selectGalleryInfoListByTypeThree(GalleryInfo galleryInfo) {
        return apiGalleryMapper.selectGalleryInfoListByTypeThree(galleryInfo);
    }


}
